import { Component } from '@angular/core';

import { NavParams, ViewController } from 'ionic-angular';

import { Config } from '../../../providers/config';

import _ from 'lodash';
import {InfoListService} from "./infoList.service";


@Component({
  selector: 'page-task-infoList',
  templateUrl: './infoList.html',
  providers: [InfoListService]
})
export class TaskInfoListPage {
	moa_page_name: any = "page-task-infoList";
  moa_page_explain: any = "流程 - 明细列表页面";

  infoList = [];

  listParams = {};

  pageTitle = "";

  noData = false;

  constructor(
    public navParams: NavParams,
    public viewCtrl: ViewController,
    private infoListService: InfoListService
  ) {
    this.listParams = this.navParams.get("listParams");

    this.pageTitle = this.listParams["fname"];

    this.infoListService.getInfoDetail(this.listParams["params"]).subscribe(datas => {
      console.log(datas);
      _.forEach(datas, d => {
        let temp = {
          datas: d,
          extand: false,
          titleFields: []
        };
        let titleFields = [];
        _.forEach(this.listParams["titleField"], t => {
          let obj = _.find(d, {label: t});
          if (obj) {
            console.log(obj);
            titleFields.push(obj["content"]);
          }
        });
        temp.titleFields = titleFields;
        this.infoList.push(temp);
      });
      if (this.infoList.length <= 0) {
        this.noData = true;
      }
    });

  }

  checkIsSelected(item) {
    item.extand = !item.extand;
  }

}
